package com.ys.malini.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.ys.malini.dao.IClassTypeDao;
import com.ys.malini.model.TClasstype;

public class ClassTypeAction extends DispatchAction {
	IClassTypeDao classTypeDao;

	public IClassTypeDao getClassTypeDao() {
		return classTypeDao;
	}

	public void setClassTypeDao(IClassTypeDao classTypeDao) {
		this.classTypeDao = classTypeDao;
	}
	public ActionForward addClassType(ActionMapping mapping, ActionForm form,HttpServletRequest request,
			HttpServletResponse response)throws Exception {
		String classType1 = request.getParameter("selClassType1");
		String classType2 = request.getParameter("selClassType2");
		String typeName = request.getParameter("txtTypeName");
		String classCode=request.getParameter("txtClassCode");
		String isMenu=request.getParameter("rdoIsMenu");
		TClasstype classType=new TClasstype();
		classType.setClassDes(typeName);
		classType.setClassCode(classCode);
		classType.setIsMenu(isMenu);
		if("".equals(classType1)){
			classType.setParantClassCode("0");
			TClasstype data=classTypeDao.add(classType);
			if(data==null){
				return mapping.findForward("fail");
			}else{
				
				return mapping.findForward("success");
			}
		}else{
			if("".equals(classType2)){
				return mapping.findForward("fail");
			
			}else{
				
				classType.setParantClassCode(classType2);
				TClasstype data=classTypeDao.add(classType);
				if(data==null){
					return mapping.findForward("fail");
				}else{
					
					return mapping.findForward("success");
				}
			}
			
		}
		

	}
}
